/**
 * 
 */
package com.java.test.user.mapper;

import com.java.test.user.dto.MemberGradeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Administrator
 *
 */
@Component
public class MemberGradeMapper {
	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<MemberGradeInfo> selectMemberGradeList() {
		String sql = "select * from member_member_grade";
		List<MemberGradeInfo> list = jdbcTemplate.query(sql, new MemberGradeInfo());
		return list;
	}

	/**
	 * 会员等级排序查询
	 * @author
	 * @date 2020/7/28 0028 15:51
	 * @return java.util.List<com.java.test.user.dto.MemberGradeInfo>
	 */
	public List<MemberGradeInfo> selectMemberGradeListOrderBy() {
		String sql = "select * from member_member_slice t order by t.count";
		List<MemberGradeInfo> list = jdbcTemplate.query(sql, new MemberGradeInfo());
		return list;
	}

	public int insertMemberGradeInfo(MemberGradeInfo info) {
		String sql = "insert into member_member_grade(member_grade_name,up_lv_exp,content)values(?,?,?)";
		int i = jdbcTemplate.update(sql, info.getMemberGradeName(), info.getUpLvExp(),info.getContent());
		return i;
	}

	public int updateMemberGradeInfo(MemberGradeInfo info) {
		String sql = "update member_member_grade set member_grade_name=?,up_lv_exp=?,content=? where id =?";
		int i = jdbcTemplate.update(sql, info.getMemberGradeName(), info.getUpLvExp(),info.getContent(),info.getId());
		return i;
	}

	public MemberGradeInfo selectMemberGradeInfoById(int id) {
		String sql = "select * from member_member_grade where id=?";
		MemberGradeInfo info = jdbcTemplate.queryForObject(sql, new MemberGradeInfo(), id);
		return info;
	}
	
	
	
}
